Reduce INFORMATION_SCHEMA calls in BigQuery get_tables_by_pattern_sql#1084
Open
emilmar wants to merge 1 commit into
Open
Reduce INFORMATION_SCHEMA calls in BigQuery get_tables_by_pattern_sql#1084emilmar wants to merge 1 commit into
emilmar wants to merge 1 commit into
Conversation
… call When `target.location` is set, use the region-qualified INFORMATION_SCHEMA.TABLES view so `table_schema` can be filtered directly. That replaces the SCHEMATA lookup + per-dataset UNION ALL with a single query. Falls back to the existing path when no location is configured, so behaviour is unchanged for those users.
Author
|
This PR was created after a discussion on undocumented rate limits in BigQuery that were hit due to dbt Fusion effectiveness. |
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Problem
On BigQuery,
dbt_utils.get_relations_by_pattern(viaget_tables_by_pattern_sql) runs two kinds ofINFORMATION_SCHEMAqueries whenever theschema_patterncontains%:INFORMATION_SCHEMA.SCHEMATAlookup to enumerate matching datasets.UNION ALLof one dataset-scopedINFORMATION_SCHEMA.TABLESquery per match.This is more work than necessary. The region-qualified
`project`.`region-X`.INFORMATION_SCHEMA.TABLESview already exposestable_schema, so the schema match can happen inside the same query as the table match.Solution
When
target.locationis set, query the region-qualifiedINFORMATION_SCHEMA.TABLESview once and filtertable_schemadirectly. TheSCHEMATAcall and theUNION ALLgo away.The existing
SCHEMATA+ iterate path is kept as a fallback for profiles without a configured location, so behaviour is unchanged for those users. The single-schema (no%) path is also unchanged. Since BigQuery is highly dependent on region, I assume most users set the target.location value. The previous version did not allow region override so it is still an improvement over that. I think we might even remove the fallback, and allow it to error instead.Note on CI coverage
integration_tests/profiles.ymldoesn't setlocation, so the existingtest_get_relations_by_patternmodel exercises the fallback path, not the new one. Happy to addlocation: USto the integration profile if maintainers want the fast path covered in CI.Checklist